using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Serialization.Surrogates;

namespace Serialization
{
    public class BinarySerializer : ISerializer
    {
        private ISurrogateSelector _selector;

        public BinarySerializer()
        {
            _selector = new DefaultSurrogateSelector();
        }

        public BinarySerializer(ISurrogateSelector selector) : this()
        {
            _selector.ChainSelector(selector);
        }

        public void Serialize(Stream serializationStream, object graph)
        {
            ObjectWriter writer = new ObjectWriter(_selector);
            writer.Write(graph, serializationStream);
        }

        public object Deserialize(Stream serializationStream)
        {
            ObjectReader reader = new ObjectReader(_selector);
            return reader.Read(serializationStream);
        }
    }
}
